//
//  WEvaluationViewController.m
//  何五路
//
//  Created by _ADY on 15/7/22.
//  Copyright (c) 2015年 _ADY. All rights reserved.
//

#import "WEvaluationViewController.h"

static LoadingView *loading = nil;

@interface WEvaluationViewController ()

@end
#define YEHight 100
#define nLString @"长度在10-500个字之间\n写下购买体会或使用过程中带来的帮助等，可以为其他小伙子提供参考～"
@implementation WEvaluationViewController
@synthesize mTableView,IntPex,aDic,imagePicker,_photos,_thumbs;
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view. 1063678069816
//    //未评价 1  已评价 2
//    if ([[NSString stringWithFormat:@"%@",[aDic objectForKey:@"ReviewsStatus"]] isEqualToString:@"1"])
//    {
//        
//    }
//    else if ([[NSString stringWithFormat:@"%@",[aDic objectForKey:@"ReviewsStatus"]] isEqualToString:@"2"])
//    {
//        
//    }
    
    RatingInt = 10;
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
    self.navigationItem.backBarButtonItem = item;
    
    mTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenMySize.size.width, screenMySize.size.height-50) style:UITableViewStyleGrouped];
    mTableView.delegate = self;
    mTableView.dataSource = self;
    mTableView.sectionHeaderHeight = 0.0;
    mTableView.sectionFooterHeight = 0.0;
    mTableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:mTableView];
    
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];//清除多余分割线
    [mTableView setTableFooterView:v];
//    
//    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
//    NSString *path=[paths  objectAtIndex:0];
//    NSString *filename=[path stringByAppendingPathComponent:@"userinfo.plist"];
//    NSMutableDictionary *remData= [NSMutableDictionary dictionaryWithContentsOfFile:filename];
    
    [self gotoBar];
}

-(void)gotoBar
{
    yesBool = NO;
    UIImage *imageD = [UIImage imageNamed:@"xzPre"];
    inButton = [UIButton buttonWithType:UIButtonTypeCustom];
    CGRect frame = CGRectMake(0,screenMySize.size.height-50+10, 100, 30);
    [inButton setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    inButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize];
    [inButton setTitle:@"匿名评价" forState:UIControlStateNormal];
    [inButton setFrame:frame];
    [inButton setTitleEdgeInsets:UIEdgeInsetsMake(0, imageD.size.width, 0, 0)];
    [inButton setImageEdgeInsets:UIEdgeInsetsMake(0, 10, 0, 0)];
    [inButton setImage:imageD forState:UIControlStateNormal];
    [inButton addTarget:self action:@selector(aInBction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:inButton];
    
    
    UIButton *xButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [xButton setFrame:CGRectMake(screenMySize.size.width-80, screenMySize.size.height-50+10, 70, 30)];
    [xButton setBackgroundImage:[UIImage imageNamed:@"enButtons"] forState:UIControlStateNormal];
    [xButton setTitle:@"提交" forState:UIControlStateNormal];
    xButton.titleLabel.font = [UIFont fontWithName:@"Arial" size:labelSize+2];
    [xButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [xButton addTarget:self action:@selector(xAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:xButton];
    
}

-(void)xAction
{
    loading = [[LoadingView alloc] initWithFrame:self.view.frame];
    [self.view addSubview:loading];
    
    if (nLtextView.text.length == 0) {
        [SendService alerViewMessage:@"请填写评价。"];
        return;
    }

    NSMutableDictionary *postDic = [NSMutableDictionary dictionary];
    
    [postDic setObject:[NSString stringWithFormat:@"%d",RatingInt/2] forKey:@"Rating"];
    [postDic setObject:[NSString stringWithFormat:@"%@",[[[aDic objectForKey:@"OrderItems"] objectAtIndex:IntPex] objectForKey:@"Id"]] forKey:@"EvaluationId"];
    [postDic setObject:nLtextView.text forKey:@"ReviewText"];

    
    NSMutableArray *myArray = [[NSMutableArray alloc] init];
    
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths  objectAtIndex:0];
    NSString *filename=[path stringByAppendingPathComponent:@"userinfo.plist"];
    NSMutableDictionary *remData= [NSMutableDictionary dictionaryWithContentsOfFile:filename];
    
    for (int i = 0 ; i < remData.count; i++)
    {
        NSMutableDictionary* mailInfoDic = [[NSMutableDictionary alloc] init];
        NSString *encodingStr = [[remData objectForKey:[NSString stringWithFormat:@"%d",i]] base64Encoding];
        [mailInfoDic setObject:encodingStr forKey:@"Code"];
        [mailInfoDic setObject:@".jpg" forKey:@"FileExtension"];
        [myArray addObject:mailInfoDic];
    }
    if(remData.count == 0)
    {
        NSMutableDictionary* mailInfoDic = [[NSMutableDictionary alloc] init];
        [mailInfoDic setObject:@"" forKey:@"Code"];
        [mailInfoDic setObject:@".jpg" forKey:@"FileExtension"];
        [myArray addObject:mailInfoDic];
    }
    [postDic setObject:myArray forKey:@"PicList"];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        NSDictionary *ret =  [SendService ProductReviewsAdd:postDic];
        dispatch_async(dispatch_get_main_queue(), ^{
            [loading closeLoading];
            if ([[NSString stringWithFormat:@"%@",[ret objectForKey:@"Result"]] isEqualToString:@"success"])
            {
                [SendService alerViewMessage:[ret objectForKey:@"Message"]];

                
            }
            else
                [SendService alerViewMessage:[ret objectForKey:@"Message"]];
        });
    });
}

-(void)aInBction
{
    yesBool = !yesBool;
    if (yesBool)
    {
        [inButton setImage:[UIImage imageNamed:@"xzPress"] forState:UIControlStateNormal];
    }else
        [inButton setImage:[UIImage imageNamed:@"xzPre"] forState:UIControlStateNormal];
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.view.backgroundColor =bgColor;
    self.title = @"评价晒单";
}

#pragma mark -
#pragma mark Table View DataSource

- (CGFloat) tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0)
        return 0.001;
    return 10;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }
    return 2;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0) {
        return YEHight;
    }
    else
    {
        if (indexPath.row == 0) {
            return YEHight/2;
        }
    }
    return YEHight*2;
}

- (UITableViewCell *)tableView:(UITableView *)aTableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"WECell";
    UITableViewCell *cell = [aTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    if (cell == nil)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        aTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
        aTableView.showsVerticalScrollIndicator = NO;
    }
    int i = (int)[[cell.contentView subviews] count] - 1;
    for(;i >= 0 ; i--)
    {
        [[[cell.contentView subviews] objectAtIndex:i] removeFromSuperview];
    }
    cell.backgroundColor = [UIColor whiteColor];
    
    if (indexPath.section == 0)
    {
        NSMutableArray *marray = [aDic objectForKey:@"OrderItems"];
        UIImageView *bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10,10, YEHight-20,YEHight-20)];
        [bgImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[marray objectAtIndex:IntPex] objectForKey:@"ProdcutPictureUrl"]]]];
        bgImageView.contentMode =  UIViewContentModeScaleAspectFit;
        [cell.contentView addSubview:bgImageView];
        
        UIImageView *bg1ImageView = [[UIImageView alloc] initWithFrame:CGRectMake(9.5,9.5, YEHight-19,YEHight-19)];
        [bg1ImageView setImage:[UIImage imageNamed:@"gwckk"]];
        [cell.contentView addSubview:bg1ImageView];
        
        [cell.contentView addSubview:[self setFrame:CGRectMake(YEHight, 10, screenMySize.size.width-YEHight-20, YEHight-40) setTitle:[NSString stringWithFormat:@"%@",[[marray objectAtIndex:IntPex] objectForKey:@"ProductName"]] setFont:labelSize setColor:[UIColor blackColor]]];
    }
    else
    {
         if (indexPath.row == 0)
         {
             [cell.contentView addSubview:[self setFrame:CGRectMake(10, (YEHight/2-30)/2, 50, 30) setTitle:@"评价:" setFont:labelSize+2 setColor:[UIColor blackColor]]];
             
             TQStarRatingView *starRatingView = [[TQStarRatingView alloc] initWithFrame:CGRectMake(60, (YEHight/2-27*1.5/2)/2, 80*1.5, 27*1.5/2) numberOfStar:5 initNum:RatingInt*40*1.5/5 setBool:NO];
             starRatingView.delegate = self;
             [cell.contentView addSubview:starRatingView];
         }
        else
        {
            if (nLtextView != nil) {
                [cell.contentView addSubview:nLtextView];
            }
            else
            {
                nLtextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, screenMySize.size.width, 70)] ;
                nLtextView.backgroundColor = [UIColor clearColor];
                nLtextView.textColor = [UIColor grayColor];
                [nLtextView setFont:[UIFont systemFontOfSize:labelSize]];
                nLtextView.returnKeyType = UIReturnKeyDone;
                nLtextView.text = nLString;
                nLtextView.delegate = self;
                nLtextView.editable = YES;
                nLtextView.scrollEnabled = YES;
                [cell.contentView addSubview:nLtextView];
            }

            NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
            NSString *path=[paths  objectAtIndex:0];
            NSString *filename=[path stringByAppendingPathComponent:@"userinfo.plist"];
            NSMutableDictionary *remData= [NSMutableDictionary dictionaryWithContentsOfFile:filename];
            
            UIScrollView *ta1ScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0,75, self.view.bounds.size.width,YEHight*2-80)];
            ta1ScrollView.backgroundColor = [UIColor clearColor];
            [ta1ScrollView setPagingEnabled:NO];
            [ta1ScrollView setShowsHorizontalScrollIndicator:NO];
            [cell.contentView addSubview:ta1ScrollView];
//            //解决UIScrollView把uitableviewcell的点击事件屏蔽start
//            ta1ScrollView.userInteractionEnabled = NO;
//            [ta1ScrollView addGestureRecognizer:ta1ScrollView.panGestureRecognizer];
//            //解决UIScrollView把uitableviewcell的点击事件屏蔽end
            
            UIImage *loginImage = [UIImage imageNamed:@"Wtjsdtp"];
            UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom];
            [loginButton setFrame:CGRectMake(10+(YEHight*2-70)*remData.count, 0, YEHight*2-80,   YEHight*2-80)];
            [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
            [loginButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [loginButton addTarget:self action:@selector(bgbuttonType) forControlEvents:UIControlEventTouchUpInside];
            [ta1ScrollView addSubview:loginButton];
            
            for (int i = 0 ; i < remData.count; i++)
            {
                
                UIImage *image = [UIImage imageWithData:[remData objectForKey:[NSString stringWithFormat:@"%d",i]]];
                
                UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10+(YEHight*2-70)*i, 0, YEHight*2-80,   YEHight*2-80)];
                [imageView setImage:image];
                [ta1ScrollView addSubview:imageView];
                
                UIButton *in1Button = [UIButton buttonWithType:UIButtonTypeCustom];
                CGRect frame = imageView.frame;
                [in1Button setFrame:frame];
                in1Button.tag = 1000+i;
                [in1Button addTarget:self action:@selector(aInAction:) forControlEvents:UIControlEventTouchUpInside];
                [ta1ScrollView addSubview:in1Button];
            }
            [ta1ScrollView setContentSize:CGSizeMake(10+(YEHight*2-70)*(remData.count+1),YEHight*2-80)];

            
        }
    }
    return cell;
}

-(void)bgbuttonType
{
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] && [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {//支持相册和照相
        
        imagePicker = [[UIImagePickerController alloc]init];
        imagePicker.delegate = self;
        [imagePicker setAllowsEditing:YES];
//        //全屏  有问题
//        CGSize screenBounds = screenMySize.size;
//        CGFloat cameraAspectRatio = 4.0f/3.0f;
//        CGFloat camViewHeight = screenBounds.width * cameraAspectRatio;
//        CGFloat scale = screenBounds.height/camViewHeight;
//        imagePicker.cameraViewTransform = CGAffineTransformMakeTranslation(0.0, (screenBounds.height- camViewHeight)/2.0);
//        imagePicker.cameraViewTransform = CGAffineTransformScale(imagePicker.cameraViewTransform, scale, scale);
//        //全屏
        
        UIActionSheet *photoSheet = [[UIActionSheet alloc] initWithTitle:@"请选择图片来源"
                                                                delegate:self
                                                       cancelButtonTitle:@"取消"
                                                  destructiveButtonTitle:nil
                                                       otherButtonTitles:@"拍照", @"相册",nil];
        
        photoSheet.actionSheetStyle=UIActionSheetStyleDefault;
        [photoSheet showInView:[UIApplication sharedApplication].keyWindow];
        
    }
    else if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary])
    {
        imagePicker = [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        [imagePicker setAllowsEditing:YES];
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //        [self presentModalViewController:imagePicker animated:YES];
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"Error accessing photo library!" delegate:nil cancelButtonTitle:@"Close" otherButtonTitles:nil];
        [alert show];
        
    }
    
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    // The user canceled -- simply dismiss the image picker.
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark    imagePicker委托方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    //    [self dismissModalViewControllerAnimated:YES];
    [self dismissViewControllerAnimated:YES completion:nil];
    
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];//原图
//    float w = image.size.width;
//    float h = image.size.height;
//    
//    if (w < 320*2 && h < 320*2) {//如果图片  宽、高都分别小于56、55  那么，直接用截好的图,因为组件会自动把图片放大
        image = [info valueForKey:UIImagePickerControllerEditedImage];
//    }
//    else
//    {//否则 就选择较短的(宽和高比较)作为标准 以中心为基准截取正方形
//        image = [info valueForKey:UIImagePickerControllerEditedImage];
//        //        w = image.size.width;
//        //        h = image.size.height;
//        //        float s = 0;
//        //        s = MIN(w, h);
////        image = [self image:image centerInSize:CGSizeMake(320*2, 320*2)];
//    }
    
    //下面就应该变为nsdata然后传给服务器了...........以下省略N个字
    //    if ([ArraySend setTheImage:image])
    {
        NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
        NSString *path=[paths  objectAtIndex:0];
        NSString *filename=[path stringByAppendingPathComponent:@"userinfo.plist"];
        NSMutableDictionary *remData= [NSMutableDictionary dictionaryWithContentsOfFile:filename];
        if (remData == nil) {
            NSMutableDictionary *remData1 = [[NSMutableDictionary alloc] init];
            NSData *imageData = UIImageJPEGRepresentation(image,0.2);
            [remData1 setObject:imageData forKey:@"0"];
            [remData1 writeToFile:filename  atomically:YES];
            [remData1 removeAllObjects];
        }
        else
        {
            NSData *imageData = UIImageJPEGRepresentation(image,0.2);
            [remData setObject:imageData forKey:[NSString stringWithFormat:@"%ld",(unsigned long)remData.count]];
            [remData writeToFile:filename  atomically:YES];
        }
        [mTableView reloadData];
        
    }
}

#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 0)
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
    else if(buttonIndex == 1)
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

//改变图片大小
- (UIImage *)image:(UIImage *)image centerInSize:(CGSize)viewsize
{
    UIGraphicsBeginImageContext(CGSizeMake(viewsize.width, viewsize.height));
    [image drawInRect:CGRectMake(0, 0, viewsize.width, viewsize.height)];
    UIImage *reSizeImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return reSizeImage;
}

-(void)aInAction:(id)sender
{
    int  type = ((UIButton*)sender).tag-100;

    NSMutableArray *photos = [[NSMutableArray alloc] init];
    NSMutableArray *thumbs = [[NSMutableArray alloc] init];
    MWPhoto *photo;
    BOOL enableGrid = YES;
    BOOL startOnGrid = NO;
    
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *path=[paths  objectAtIndex:0];
    NSString *filename=[path stringByAppendingPathComponent:@"userinfo.plist"];
    NSMutableDictionary *remData= [NSMutableDictionary dictionaryWithContentsOfFile:filename];
    for (int i = 0; i < remData.count; i ++)
    {
        photo = [MWPhoto photoWithImage:[UIImage imageWithData:[remData objectForKey:[NSString stringWithFormat:@"%d",i]]]];
        [thumbs addObject:photo];
        photo.caption =nil;
        [photos addObject:photo];

    }
    
    self._photos = photos;
    self._thumbs = thumbs;
    // Create browser
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    browser.displayActionButton = YES;//分享按钮,默认是
    browser.displayNavArrows = YES;//左右分页切换,默认否
    browser.displaySelectionButtons = NO;//是否显示选择按钮在图片上,默认否
    browser.alwaysShowControls = NO;//控制条件控件 是否显示,默认否
    browser.zoomPhotosToFill = YES;//是否全屏,默认是
#if __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_7_0
    browser.wantsFullScreenLayout = YES;
#endif
    browser.enableGrid = enableGrid;
    browser.startOnGrid = startOnGrid;
    browser.enableSwipeToDismiss = YES;
    [browser setCurrentPhotoIndex:type];
    
    // Reset selections
    if (photos.count>0) {
        _selections = [NSMutableArray new];
        for (int i = 0; i < photos.count; i++) {
            [_selections addObject:[NSNumber numberWithBool:NO]];
        }
    }
    [self.navigationController pushViewController:browser animated:YES];
    
    
}

#pragma mark - MWPhotoBrowserDelegate

- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser thumbPhotoAtIndex:(NSUInteger)index {
    if (index < _thumbs.count)
        return [_thumbs objectAtIndex:index];
    return nil;
}

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser didDisplayPhotoAtIndex:(NSUInteger)index {
    //    NSLog(@"Did start viewing photo at index %lu", (unsigned long)index);
}

- (BOOL)photoBrowser:(MWPhotoBrowser *)photoBrowser isPhotoSelectedAtIndex:(NSUInteger)index {
    return [[_selections objectAtIndex:index] boolValue];
}

//- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index {
//    return [NSString stringWithFormat:@"Photo %lu", (unsigned long)index+1];
//}

- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index selectedChanged:(BOOL)selected {
    [_selections replaceObjectAtIndex:index withObject:[NSNumber numberWithBool:selected]];
    //    NSLog(@"Photo at index %lu selected %@", (unsigned long)index, selected ? @"YES" : @"NO");
}

- (void)photoBrowserDidFinishModalPresentation:(MWPhotoBrowser *)photoBrowser {
    // If we subscribe to this method we must dismiss the view controller ourselves
    //    NSLog(@"Did finish modal presentation");
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark - textview delegate
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text
{
    if ([text isEqualToString:@"\n"])
    {
        [textView resignFirstResponder];
        return NO;
    }
    if (range.location < 500)
    {
        return YES;
    }
    else
        textView.text = [textView.text substringToIndex:[textView.text length] - 1];
    return YES;
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    [mTableView setContentOffset:CGPointMake(0, 100) animated:YES];

    if ([textView.text  isEqualToString:nLString] ) {
        textView.text = @"";
    }
    
    return YES;
}

- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
    [mTableView setContentOffset:CGPointMake(0, 0) animated:YES];
    if (textView.text.length == 0)
    {
        textView.text = nLString;
    }
    
    [textView resignFirstResponder];
    return YES;
}

#pragma mark 星星
-(void)starRatingView:(TQStarRatingView *)view score:(float)score
{
    RatingInt = (int)score*10;
    NSLog(@"%@",[NSString stringWithFormat:@"%0.2f",score*10]);
}



-(UILabel*)setFrame:(CGRect)frame setTitle:(NSString*)title setFont:(int)font setColor:(UIColor*)myColor
{
    title = [title stringByReplacingOccurrencesOfString:@"<null>" withString:@""];
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:frame];
    if (title != nil)
        titleLabel.text = [NSString stringWithFormat:@"%@",title];
    titleLabel.textAlignment = 0;
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont fontWithName:@"Arial" size:font];
    titleLabel.textColor = myColor;
    return titleLabel;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
